package com.weseal.dry.controller;

import com.weseal.dry.vo.CategoryVo;
import common.response.CommonResult;
import common.response.PageResponseResult;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

/**
 * @title
 * @description
 * @usage
 * @copyright Copyright 2014  rrmj Corporation. All rights reserved.
 * @company 上海众多美网络科技有限公司
 * @author weseal
 * @create 2018/4/8
 */
@RequestMapping("/category")
@Controller
public class CategoryController {

	private static List<CategoryVo> categoryVoList = new ArrayList<CategoryVo>();
	static {
		CategoryVo categoryVo1 = new CategoryVo("1","西装");
		CategoryVo categoryVo2 = new CategoryVo("2","皮草");
		CategoryVo categoryVo3 = new CategoryVo("3","裙/库");
		categoryVoList.add(categoryVo1);
		categoryVoList.add(categoryVo2);
		categoryVoList.add(categoryVo3);
	}


	@RequestMapping(value = "/list")
	public String list(ModelMap map){
		PageResponseResult<CategoryVo> result = new PageResponseResult<CategoryVo>();
		result.setData(categoryVoList);
		map.put("response", result);
		return "category/list";
	}

	@RequestMapping(value = "/delete",method = RequestMethod.POST)
	@ResponseBody
	public CommonResult delete(String id){
		categoryVoList.remove(0);
		return CommonResult.installSuccess();
	}

	@RequestMapping(value = "/create",method = RequestMethod.POST)
	@ResponseBody
	public CommonResult create(@RequestParam("categoryName") String categoryName){
		CategoryVo  categoryVo1= new CategoryVo("1",categoryName);
		categoryVoList.add(categoryVo1);
		return CommonResult.installSuccess();
	}


}
